<?php

namespace App\Http\Controllers\Admin;

use App\Post;
use Illuminate\Http\Request;

class PostController extends Controller
{

    //文章审核模块
    public function index()
    {

        $posts = Post::withoutGlobalScope('avaiable')->where('status', 0)->orderBy('created_at', 'desv')->paginate(10);

        return view('admin.post.index', compact('posts'));
    }

    //文章审核行为
    public function status(Post $post)
    {
        $this->validate(request(), [
            "status" => 'required|in:-1,1',
        ]);

        $post->status = request('status');

        $re =  $post->save();


        if(!$re) return response()->json(['error' => 200, 'msg' => '审核失败']);

         return response()->json(['error' => 0, 'msg' => '']);

    }
}
